﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace PetGo
{
    class Program
    {
        static void Main(string[] args)
        {
            Game theGame = new Game(7.5, 10);
            Board theBoard = new Board(9, theGame);
            theGame.myBoard = theBoard;
            // GTP Modus
            if (args != null && args.Length > 0)
            {
                foreach(string theopt in args)
                {
                    switch (theopt.ToLower().Substring(0,5))
                    {
                        case "-gtpm":
                            theGame.myisGTP = true;
                            break;
                        case "-gtpd":
                            theGame.myisGTPDebug = true;
                            break;
                        case "-time":
                            theGame.mysecondstothink = int.Parse(theopt.ToLower().Replace("-time",""));
                            break;
                        case "-size":
                            theBoard.myboardsize = int.Parse(theopt.ToLower().Replace("-size", ""));
                            break;
                        case "-regr":
                            theGame.myRegression = int.Parse(theopt.ToLower().Replace("-regr", ""));
                            break;
                        default:
                            break;
                    }
                }
            }
            if (theBoard.myboardsize == 19)
            {
                Pattern.buildPattern(theGame);
            }
            if (theGame.myRegression > 0)
            {
                theGame.regression();
            }
            else
            {
                if (theGame.myisGTP)
                {
                    ThreadPool.QueueUserWorkItem(new Program().readConsole, theGame);
                    theGame.doit();
                }
                else
                {
                    theGame.play();
                }
            }
            return;

            
        }
        /// <summary>
        /// Thread to Read the Console
        /// </summary>
        /// <param name="it"></param>
        public void readConsole(Object it)
        {
            while (true)
            {
                Game tempGame = it as Game;
                if (Game.myInput == "")
                {
                    Game.myInput = Console.ReadLine();
                }
                Thread.Sleep(10);
            }
        }
    }
}
